<template>
    <div class="e-form">
        <BillTop title="调价结算编辑" @cancel="handleClose"></BillTop>
        <div class="tabs warningTabs" v-if="Object.keys(formData).length != 0">
            <el-tabs
                tab-position="left"
                v-model="tabsName"
                @tab-click="onChangeTab"
            >
                <!-- 基本信息 -->
                <el-tab-pane
                    label="基本信息"
                    name="baseInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="结算明细"
                    name="settlement"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="服务费用"
                    name="serviceCharge"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="附件信息"
                    name="accessory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="审核历史"
                    name="auditHistory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <div>
                    <!-- 基本信息 -->
                    <div id="baseInfoCon" class="con">
                        <div class="e-form">
                            <div class="tabs">
                                <div class="tabs-title" id="baseInfo">
                                    基本信息
                                </div>
                                <div style="width: 100%" class="form">
                                    <el-form
                                        :model="formData"
                                        label-width="150px"
                                        :rules="formDataRules"
                                        ref="formDataRef"
                                    >
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="结算编号">
                                                    {{ formData.billNo }}
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="单据机构">
                                                    {{ formData.orgName }}
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算类型"
                                                    prop="businessType"
                                                >
                                                    <el-select
                                                        v-model="
                                                            formData.businessType
                                                        "
                                                        placeholder="请选择"
                                                        v-if="!isRedSingle"
                                                        @change="
                                                            businessTypeChange
                                                        "
                                                    >
                                                        <el-option
                                                            v-for="item in businessTypeList"
                                                            :key="item.value"
                                                            :label="item.key"
                                                            :value="item.value"
                                                        >
                                                        </el-option>
                                                    </el-select>
                                                    <span v-else>{{
                                                        businessType
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="源单编号">
                                                    <!-- <el-input
                                                        v-model="
                                                            formData.sourceBillNo
                                                        "
                                                        readonly
                                                        v-if="!isRedSingle"
                                                    >
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="
                                                                sourceBillNoClick
                                                            "
                                                            v-show="
                                                                formData.sourceBillId
                                                            "
                                                        ></i>
                                                    </el-input> -->
                                                    <span>
                                                        {{
                                                            formData.sourceBillNo
                                                        }}
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="
                                                                sourceBillNoClick
                                                            "
                                                            v-if="
                                                                formData.sourceBillNo
                                                            "
                                                        ></i>
                                                    </span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算单位"
                                                    prop="settlementUnitName"
                                                >
                                                    <el-input
                                                        v-model="
                                                            formData.settlementUnitName
                                                        "
                                                        readonly
                                                        v-if="!isRedSingle"
                                                    >
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="
                                                                settlementUnitNameClick
                                                            "
                                                        ></i>
                                                    </el-input>
                                                    <span v-else>{{
                                                        formData.settlementUnitName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算日期"
                                                    prop="settlementDate"
                                                >
                                                    <el-date-picker
                                                        v-model="
                                                            formData.settlementDate
                                                        "
                                                        type="date"
                                                        placeholder="选择日期"
                                                        value-format="yyyy-MM-dd"
                                                        :clearable="false"
                                                        v-if="!isRedSingle"
                                                    >
                                                    </el-date-picker>
                                                    <span v-else>{{
                                                        formData.settlementDate
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="结算金额(元)"
                                                    prop="amount"
                                                >
                                                    {{ formData.amount }}
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="验收人员">
                                                    <el-input
                                                        v-model="
                                                            formData.acceptancePersonnelName
                                                        "
                                                        readonly
                                                        v-if="!isRedSingle"
                                                    >
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-input__icon
                                                                el-icon-document-copy
                                                            "
                                                            @click="
                                                                acceptancePersonnelNameClick
                                                            "
                                                        ></i>
                                                    </el-input>
                                                    <span v-else>{{
                                                        formData.acceptancePersonnelName
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="发票编号">
                                                    <el-input
                                                        placeholder="请填写发票编号"
                                                        v-model="
                                                            formData.invoiceNo
                                                        "
                                                        v-enterInteger1
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.invoiceNo
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="服务费用(含税,元)"
                                                >
                                                    {{ formData.freight }}
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税率%"
                                                    prop="taxRate"
                                                >
                                                    <el-input
                                                        placeholder="请填写"
                                                        v-model="
                                                            formData.taxRate
                                                        "
                                                        @input.native="
                                                            onInput0_100
                                                        "
                                                        v-enter-float="{
                                                            set: formData,
                                                            key: 'taxRate'
                                                        }"
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.taxRate
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税价合计"
                                                    prop="totalAmount"
                                                >
                                                    {{ formData.totalAmount }}
                                                    元
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="税额"
                                                    prop="taxAmount"
                                                >
                                                    <el-input
                                                        placeholder="请填写"
                                                        v-model="
                                                            formData.taxAmount
                                                        "
                                                        v-enter-float="{
                                                            set: formData,
                                                            key: 'taxAmount'
                                                        }"
                                                        v-if="!isRedSingle"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.taxAmount
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="税额差额">
                                                    {{ formData.taxDifference }}
                                                    元
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="币种"
                                                    prop="currency"
                                                >
                                                    {{ formData.currency }}
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="本位币"
                                                    prop="baseCurName"
                                                >
                                                    {{ formData.baseCurName }}
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="传财务共享"
                                                >
                                                    {{ formData.easId ? '已传' : '未传'}}
                                                </el-form-item>
                                            </el-col>

                                            <el-col :span="12">
                                                <el-form-item
                                                    label="本位币汇率"
                                                    prop="baseCurRate"
                                                >
                                                    <el-input
                                                        placeholder="请填写"
                                                        v-model="
                                                            formData.baseCurRate
                                                        "
                                                        v-enter-float2="{
                                                            set: formData,
                                                            key: 'baseCurRate'
                                                        }"
                                                        v-if="
                                                            !isBaseCurRate && !isRedSingle"
                                                        @blur="baseCurRateBlur"
                                                    ></el-input>
                                                    <span v-else>{{
                                                        formData.baseCurRate
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-form-item label="备注">
                                                <el-input
                                                    type="textarea"
                                                    :rows="2"
                                                    resize="none"
                                                    placeholder="请输入内容"
                                                    v-model="formData.remarks"
                                                    maxlength='500'
                                                >
                                                </el-input>
                                            </el-form-item>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="状态">
                                                    {{
                                                        showState(
                                                            formData.state
                                                        )
                                                    }}
                                                    <!-- 草稿/审核中/已审核/已关闭/已作废 -->
                                                </el-form-item>
                                            </el-col>
                                            <el-col
                                                :span="12"
                                                v-if="
                                                    formData.redBillState !== -1
                                                "
                                            >
                                                <el-form-item label="冲红单">
                                                    <span
                                                        :style="
                                                            redBillStateStyle
                                                        "
                                                        >{{
                                                            redBillStateFun
                                                        }}</span
                                                    >
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </div>
                            </div>
                        </div>

                        <!-- ------------------------------------------------------------------------------------- -->
                    </div>

                    <!-- 结算明细 -->
                    <div id="settlementCon" class="con">
                        <div class="tabs-title" id="settlement">结算明细</div>
                        <div class="e-table">
                            <div
                                class="errorMsg"
                                v-if="errorSettlementMsg.length > 0"
                            >
                                <span>
                                    {{ errorSettlementMsg.join(',') }}
                                </span>
                            </div>
                            <el-table
                                :data="settlementData"
                                border
                                style="width: 100%"
                                ref="settlementTable"
                                :row-class-name="tableRowClassName"
                                @selection-change="acceptanceSelect"
                                :tree-props="{
                                    children: 'children',
                                    hasChildren: 'hasChildren'
                                }"
                                row-key="uuid"
                                :max-height="$store.state.tableHeight"
                                v-sortTable="{ 'tableData': settlementData, '_this': this, 'ref': 'settlementTable' }"
                            >
                                <el-table-column
                                    prop="materialClassName"
                                    label="物资类别"
                                    min-width="170"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="materialName"
                                    label="物资名称"
                                    min-width="130"
                                >
                                </el-table-column>
                                <el-table-column prop="spec" label="规格">
                                </el-table-column>
                                <el-table-column prop="texture" label="材质">
                                </el-table-column>
                                <el-table-column prop="unit" label="计量单位">
                                </el-table-column>
                                <el-table-column
                                    prop="warehouseName"
                                    label="仓库"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="settledQuantity"
                                    label="调价结算数量"
                                    width="100"
                                >
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.settledQuantity"
                                            v-enter-float2="{
                                                set: row,
                                                key: 'settledQuantity'
                                            }"
                                            placeholder=""
                                            @blur="settledQuantityBlur(row)"
                                            v-if="!row.children && !isRedSingle"
                                        ></el-input>
                                        <span v-else>{{
                                            row.settledQuantity
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="调价验收单价(元)"
                                    width="150"
                                    prop="acceptancePrice"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="settledPrice"
                                    label="调价结算单价(元)"
                                    width="150"
                                >
                                </el-table-column>
                                <el-table-column
                                    label="调价结算不含税金额(元)"
                                    width="170"
                                    prop="settledAmount"
                                >
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.settledAmount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'settledAmount'
                                            }"
                                            placeholder=""
                                            @blur="settledAmountBlur(row)"
                                            v-if="!row.children && !isRedSingle"
                                        ></el-input>
                                        <span v-else>{{
                                            row.settledAmount
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="价差(元)"
                                    width="120"
                                    prop="difference"
                                >
                                </el-table-column>
                                <el-table-column
                                    label="税额差额(元)"
                                    width="120"
                                    prop="taxDifference"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>

                    <!-- 服务费用 -->
                    <div id="serviceChargeCon" class="con">
                        <div class="tabs-title" id="serviceCharge">
                            服务费用
                        </div>
                        <div class="e-table">
                            <div
                                class="top"
                                v-if="!isRedSingle && isServiceFee"
                            >
                                <div class="left">
                                    <div>
                                        <el-button
                                            size="mini"
                                            class="btn-blue"
                                            @click="serviceFeeAdd"
                                            >新增行</el-button
                                        >
                                        <el-button
                                            size="mini"
                                            class="btn-delete"
                                            @click="serviceFeeDeleteClick"
                                            >批量删除</el-button
                                        >
                                    </div>
                                </div>
                            </div>
                            <div
                                class="errorMsg"
                                v-if="errorServiceFeeMsg.length > 0"
                            >
                                <span>
                                    {{ errorServiceFeeMsg.join(',') }}
                                </span>
                            </div>
                            <el-table
                                :data="serviceFeeData"
                                border
                                style="width: 100%"
                                :row-class-name="tableRowClassNameF"
                                @selection-change="serviceFeeSelect"
                                ref="serviceFeeTable"
                                :max-height="$store.state.tableHeight"
                                v-sortTable="{ 'tableData': serviceFeeData, '_this': this, 'ref': 'serviceFeeTable' }"
                            >
                                <el-table-column
                                    type="selection"
                                    width="55"
                                    v-if="!isRedSingle"
                                >
                                </el-table-column>
                                <el-table-column
                                    label="操作"
                                    fixed
                                    width="100px"
                                    align="left"
                                    v-if="!isRedSingle"
                                >
                                    <template slot-scope="{ row, $index }">
                                        <div class="handle">
                                            <div
                                                style="cursor: pointer"
                                                class="list_box"
                                            >
                                                <img
                                                    src="@/assets/btn/delete.png"
                                                    class="add_sub"
                                                    title="删除"
                                                    @click="
                                                        serviceFeeDelete(
                                                            row,
                                                            $index
                                                        )
                                                    "
                                                />
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="合同编号"
                                    fixed
                                    min-width="150"
                                >
                                    <template v-slot="{ row, $index }">
                                        {{ row.contractBillNo }}
                                        <i
                                            style="
                                                cursor: pointer;
                                                font-size: 20px;
                                            "
                                            class="el-icon-document-copy"
                                            @click="contractDialog(row, $index)"
                                            v-if="!isRedSingle"
                                        ></i>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    label="结算单位"
                                    min-width="190"
                                >
                                    <template v-slot="{ row, $index }">
                                        {{ row.settlementUnitName }}
                                        <i
                                            style="
                                                cursor: pointer;
                                                font-size: 20px;
                                            "
                                            class="el-icon-document-copy"
                                            @click="
                                                billingUnitDialog(row, $index)
                                            "
                                            v-if="!isRedSingle"
                                        ></i>
                                    </template>
                                </el-table-column>
                                <el-table-column label="清单名称" width="150">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.contractDtlName"
                                            placeholder=""
                                            v-if="
                                                !isRedSingle &&
                                                !row.contractBillNo
                                            "
                                            @blur="contractDtlNameBlur"
                                        ></el-input>
                                        <span v-else>{{
                                            row.contractDtlName
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="数量" width="100">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.quantity"
                                            v-enter-float2="{
                                                set: row,
                                                key: 'quantity'
                                            }"
                                            placeholder=""
                                            @blur="quantityBlur(row)"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.quantity }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="price"
                                    label="单价(元)"
                                    width="100"
                                >
                                </el-table-column>
                                <el-table-column label="金额(元)" width="100">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.amount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'amount'
                                            }"
                                            placeholder=""
                                            @blur="amountBlur(row)"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.amount }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="发票编号" width="130">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.invoiceNo"
                                            v-enterInteger1
                                            placeholder=""
                                            @blur="invoiceNoBlur(row)"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.invoiceNo }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="税率%" width="130">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.taxRate"
                                            v-enter-float="{
                                                set: row,
                                                key: 'taxRate'
                                            }"
                                            placeholder=""
                                            @blur="taxRateBlur(row)"
                                            @input.native="onInput0_100"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.taxRate }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="税额（元）" width="130">
                                    <template v-slot="{ row }">
                                        <el-input
                                            v-model="row.taxAmount"
                                            v-enter-float="{
                                                set: row,
                                                key: 'taxAmount'
                                            }"
                                            placeholder=""
                                            @blur="taxAmountBlur(row)"
                                            v-if="!isRedSingle"
                                        ></el-input>
                                        <span v-else>{{ row.taxAmount }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="totalAmount"
                                    label="税价合计（元）"
                                    width="130"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                    <!-- 附件信息 -->
                    <div id="accessoryCon" class="con">
                        <div class="tabs-title" id="accessory">附件信息</div>
                        <attach-comp
                            :relationId="billid"
                            bucketName="materialsettle"
                            v-if="objFlag.flag5"
                            :isView="formData.redBillState != 3 ? false : true"
                        />
                        <div class="seize-a-seat" v-else>
                            <i class="el-icon-loading"></i>
                        </div>
                    </div>
                    <!-- 审核历史 -->
                    <div id="auditHistoryCon" class="con">
                        <div class="tabs-title" id="auditHistory">审核历史</div>
                        <AcceptanceHistory
                            :billType="1036"
                            :billId="billid"
                        ></AcceptanceHistory>
                    </div>
                </div>
            </el-tabs>
        </div>
        <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
        <div class="buttons">
            <!-- <el-button
                type="primary"
                style="background: #2e61d7"
                v-if="formData.state == 1 || formData.state == 9"
                >打印</el-button
            > -->
            <el-button
                type="primary"
                style="background: #2e61d7"
                v-if="formData.state == 2 && formData.redBillState == -1"
                >冲红单</el-button
            >
            <exaButtons
                :auditState="auditState"
                @exas="exas"
                :state="formData.state"
                :founderId="formData.founderId"
            ></exaButtons>
            <el-button @click="handleClose">关闭</el-button>
        </div>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapMutations, mapState } from 'vuex'
import { showLoading, hideLoading, openAppClient } from '@/utils/common'
import AttachComp from '@/components/common/attachIndex'
import request from '@/api/materials/materialAcceptance'
import priceSetRequest from '@/api/materialSettlement/priceSettlement'
import { getUuid } from '@/utils/common'
import AcceptanceHistory from '@/pages/materialsmanagement/checkAdmin/AcceptanceHistory'
import exaButtons from '@/components/common/exaButtons'

export default {
    components: {
        AttachComp,
        AcceptanceHistory,
        exaButtons
    },
    data () {
        return {
            tabsName: 'baseInfo',
            settlementData: [], // 结算明细数据
            serviceFeeData: [], //服务费用数据
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //基本信息表单数据
            formData: {
                acceptancePersonnelId: '',
                acceptancePersonnelName: '',
                amount: '',
                baseCurAmount: 0,
                baseCurFreight: 0,
                baseCurId: '',
                baseCurName: '',
                baseCurRate: '',
                baseCurTaxAmount: 0,
                baseCurTotalAmount: 0,
                billId: '',
                billNo: '',
                businessType: 0,
                currency: '',
                currencyId: '',
                easId: '',
                evaluationLevel: '',
                founderId: '',
                founderName: '',
                freight: '',
                gmtCreate: '',
                gmtModified: '',
                invoiceNo: '',
                isRed: 0,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                orgId: '',
                orgName: '',
                redBillId: '',
                redBillNo: '',
                redBillState: null,
                remarks: '',
                rmbAmount: 0,
                rmbFreight: 0,
                rmbId: '',
                rmbName: '',
                rmbRate: 0,
                rmbTaxAmount: 0,
                rmbTotalAmount: 0,
                settlementDate: '',
                settlementUnitId: '',
                settlementUnitName: '',
                sourceBillId: '',
                sourceBillNo: '',
                sourceId: '',
                sourceNumber: '',
                state: 0,
                taxAmount: '',
                taxDifference: '',
                taxRate: '',
                totalAmount: '',
                workId: ''
            },
            objFlag: {
                flag5: false
            },
            billid: '',
            orgId: '', //机构id
            orgName: '', //机构名称
            businessTypeList: [
                {
                    value: 0,
                    key: '零星采购计划'
                },
                {
                    value: 1,
                    key: '物资采购合同'
                },
                {
                    value: 2,
                    key: '调入（调拨单）'
                }
            ],
            formDataRules: {
                businessType: [
                    {
                        required: true,
                        message: '请选择业务类型',
                        trigger: 'blur'
                    }
                ],
                settlementUnitName: [
                    {
                        required: true,
                        message: '请选择结算单位',
                        trigger: 'blur'
                    }
                ],
                amount: [
                    {
                        required: true,
                        message: '请输入验收金额',
                        trigger: 'blur'
                    }
                ],
                taxRate: [
                    { required: true, message: '请输入税率', trigger: 'blur' }
                ],
                taxAmount: [
                    { required: true, message: '请输入税额', trigger: 'blur' }
                ],
                totalAmount: [
                    {
                        required: true,
                        message: '请输入税价合计',
                        trigger: 'blur'
                    }
                ],
                freight: [
                    {
                        required: true,
                        message: '请输入服务费用',
                        trigger: 'blur'
                    }
                ],
                currency: [
                    {
                        required: true,
                        message: '请根据选择的结算明细带入币种',
                        trigger: 'blur'
                    }
                ],
                invoiceNo: [
                    {
                        required: true,
                        message: '请填写发票号',
                        trigger: 'blur'
                    }
                ],
                baseCurName: [
                    {
                        required: true,
                        message: '请根据选择的结算明细带入本位币',
                        trigger: 'blur'
                    }
                ],
                baseCurRate: [
                    {
                        required: true,
                        message: '请根据选择的结算明细带入本位币汇率',
                        trigger: 'blur'
                    }
                ]
            },
            auditState: {},
            auditParams: {
                // 审核
                billId: '',
                billType: '1036',
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: '',
                orgId: '',
                orgName: '',
                userId: '',
                workId: ''
            },
            nullifyParams: {
                // 作废
                billId: this.$route.query.billid,
                billType: '1036',
                nullifyDescription: '',
                nullifyReason: '',
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: ''
            },
            errorList: [], //控制导航栏感叹号的显示
            errorSettlementMsg: [], // 结算明细
            errorServiceFeeMsg: [], // 服务费用
            redBillStateStyle: {
                width: '300px',
                height: '30px',
                color: '#fff',
                backgroundColor: '',
                'text-align': 'center'
            },
            redFormData: null,
            jsdwData: {
                businessUnitTypes: [],
                keyword: '',
                limit: 10,
                orgId: '',
                outerTypes: [],
                page: 1,
                states: [],
                type: [0, 1, 2],
                supplierTypes: [],
                subcontractorTypes: [],
                businessTypes: []
            },
            jsdwIds: null,
            isSubmit: false,
            settlementList: [], // 验收已选数据
            serviceFeeList: [], // 服务费用已选数据
            settlementDelData: [],
            isServiceFee: false,
            isRedSingle: false,
            isBaseCurRate: true,
            businessType: '',
            unwatch1: null,
            unwatch2: null
        }
    },
    computed: {
        ...mapState({
            currencyForm: state => state.equip.equipData.currencyForm //币种
        }),
        //状态
        // statusLable () {
        //     return param => {
        //         const state = this.$store.state.settlementManagement.ysState
        //         const obj = state.find(x => x.value == param)
        //         return obj ? obj.label : ''
        //     }
        // },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 100 - this.lastConHeight
        },
        // 红单状态
        redBillStateFun () {
            let redState = ''
            switch (this.formData.redBillState) {
            case 0:
                redState = '冲销中'
                break
            case 1:
                redState = '冲销中'
                break
            case 2:
                redState = '已冲销'
                break
            case 3:
                redState = '红单'
                break
            }
            return redState
        }
    },
    watch: {
        // 本位币和币种一样的时候，值为1；不一样的时候，填写正数，不能为0，保留4位小数
        'formData.currency' (newData, oldData) {
            if (this.formData.currency == this.formData.baseCurName) {
                this.isBaseCurRate = true
                this.formData.baseCurRate = 1
            } else {
                this.isBaseCurRate = false
                if (oldData != '') {
                    this.formData.baseCurRate = null
                }
            }
        },
        //给错误标签加上提醒
        errorList: newData => {
            const tabs = document.querySelectorAll('.el-tabs__item')
            tabs.forEach(DOM => {
                const { childNodes } = DOM
                if (childNodes.length > 1) {
                    DOM.removeChild(childNodes[1])
                }
            })
            newData.forEach(item => {
                const itemDom = document.querySelector(`#tab-${item}`)
                var element = document.createElement('i')
                element.className = 'el-icon-warning-outline warning'
                itemDom.appendChild(element)
            })
        },
        'formData.redBillState' () {
            if (this.formData.redBillState == 3) {
                this.redBillStateStyle.backgroundColor = '#FF2300'
            } else if (
                this.formData.redBillState == 0 ||
                this.formData.redBillState == 1
            ) {
                this.redBillStateStyle.backgroundColor = '#FFA40D'
            } else if (this.formData.redBillState == 2) {
                this.redBillStateStyle.backgroundColor = 'rgb(153,153,153)'
            }
        },
        // 监听结算明细的子级是否有数据, 如果没有数据,则服务费用处不显示新增和删除按钮
        settlementData: {
            handler: function () {
                if (this.settlementData.length < 1) {
                    this.isServiceFee = false
                    this.formData.sourceBillId = ''
                } else {
                    // 如果每一个子项的changeType都为 -1  就说明都删除了, 那服务费用就不能显示 新增/删除按钮
                    let arr = []
                    this.settlementData.forEach(item => {
                        let isData = item.children.every(
                            its => its.changeType === -1
                        )
                        arr.push(isData)
                    })
                    let isSubmit = arr.every(i => i === true)
                    if(isSubmit) {
                        this.isServiceFee = false
                        this.formData.sourceBillId = ''
                    }else {
                        this.isServiceFee = true
                    }
                }
            },
            deep: true
        },
        // 监听结算明细的子级是否有数据, 如果结算明细删除至没有数据,那么服务费用中如果有数据则需要删除服务费用中的数据
        isServiceFee () {
            if (!this.isServiceFee) {
                for (let i = 0; i < this.serviceFeeData.length; i++) {
                    if (this.serviceFeeData[i]['dtlId']) {
                        this.$set(this.serviceFeeData[i], 'changeType', -1)
                        this.$set(this.serviceFeeData[i], 'amount', 0)
                        this.$set(this.serviceFeeData[i], 'totalAmount', 0)
                    } else {
                        this.serviceFeeData.splice(i, 1)
                        i--
                    }
                }
            }
        },
    },
    created () {
        let data = JSON.parse(localStorage.getItem('vuex'))
        this.orgId = data.userInfo.orgInfo.orgId
        this.orgName = data.userInfo.orgInfo.orgName
        this.billid = this.$route.query.billid
        this.auditParams.billId = this.$route.query.billid
        this.getAllData()
    },
    mounted () {
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()

        // 保存所有tabName
        const arr = [
            'baseInfo',
            'settlement',
            'serviceCharge',
            'accessory',
            'auditHistory'
        ]
        this.tabArr = arr
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const $item = document.getElementById(item)
                    let itemTop = null
                    if ($item) {
                        itemTop = $item.offsetTop + 20
                    }
                    return itemTop
                })
            }
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 50 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })
        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })

            console.log($idsTop)
        })
        this.scorllDtl()
    },
    methods: {
        ...mapMutations(['setPopConfirm', 'setAuditParams', 'setSelectedInfo']),
        //如果是新增后,直接跳转到编辑页的情况需要跳转到第二个标签
        scorllDtl () {
            if (this.$route.query.name) {
                setTimeout(() => {
                    //因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                    let obj = {
                        name: this.$route.query.name
                    }
                    this.tabsName = this.$route.query.name
                    this.onChangeTab(obj)
                }, 200)
            }
        },
        getAllData () {
            showLoading()
            Promise.all([
                this.getBasicData(), //进入页面就获取基本信息数据
                this.getAttach(), // 附件列表
                this.getUnitInfo() // 获取按钮状态
            ]).finally(() => {
                hideLoading()
            })
        },

        //获取基本信息数据
        async getBasicData () {
            let data = await priceSetRequest.getBasicInfo(this.billid)
            this.redFormData = this._.cloneDeep(data)
            if (data.redBillState == '3') {
                // 如果是3,说明进入该单据是红单进入到编辑页
                this.businessType = this.businessTypeList.find(
                    item => item.value === data.businessType
                ).key
                this.formData = data
                this.isRedSingle = true
            } else {
                this.formData = data
            }

            // 开启结算金额(元)的监听
            this.$watch('formData.amount', () => {
                // 税额 = 结算金额 * 税率
                this.formData.taxAmount = +(
                    +this.formData.amount *
                    (+this.formData.taxRate / 100)
                ).toFixed(2)
                // 税价合计 = 结算金额 + 税额
                this.formData.totalAmount = +(
                    (+this.formData.amount * 100 +
                        +this.formData.taxAmount * 100) /
                    100
                ).toFixed(2)
                // 结算金额(本位币) = 结算金额 * 本位币汇率
                this.formData.baseCurAmount = +(
                    +this.formData.amount * +this.formData.baseCurRate
                ).toFixed(2)
            })
            // 监听税率, 税额 = 结算金额 * 税率
            this.$watch('formData.taxRate', () => {
                this.formData.taxAmount = +(
                    +this.formData.amount *
                    (+this.formData.taxRate / 100)
                ).toFixed(2)
                // 税率变化后, 结算明细中税额随之变化
                this.settlementData.forEach(item => {
                    item.children.forEach(it => {
                        it.taxAmount = +(+it.settledAmount * (+this.formData.taxRate / 100)).toFixed(2)
                        it.taxDifference = +(+it.taxAmount - +it.acceptanceTaxAmount).toFixed(2)
                    })
                })
                this.taxDifferenceFn()
            })
            // 监听税额
            this.$watch('formData.taxAmount', () => {
                // 税价合计 = 验收金额+税额
                this.formData.totalAmount = +(+this.formData.amount + +this.formData.taxAmount).toFixed(2)
                // 计算基本信息中的税额差额
                this.taxDifferenceFn()
            })
            // 监听服务费用的税价合计
            this.$watch('serviceFeeData', () => {
                this.formData.freight = +(this.serviceFeeData.reduce((prev, c) => prev += (+c.totalAmount || 0), 0)).toFixed(2)
            }, { deep: true })

            await this.getSettlementList() // 结算明细表格数据
            await this.getServeList() // 服务费用表格数据
        },

        // 源单编号-跳转到现场收料的详情页
        sourceBillNoClick () {
            let url = ''
            let name = ''
            switch (this.formData.businessType) {
            case 0:
                url = '/sporadicPurchaseParticulars'
                name = '查看零星采购计划'
                break
            case 1:
                url = '/ctMaterialApplyShow'
                name = '查看物资采购合同'
                break
            case 2:
                url = '/revolveAllocationShow'
                name = '查看调入(调拨单)'
                break
            }
            openAppClient(
                `${url}?billid=${this.formData.sourceBillId}&isview=${true}`,
                `${name}`
            )
        },
        // 选择验收人员
        async acceptancePersonnelNameClick () {
            let data = await request.getAcceptancerName()
            this.formData.acceptancePersonnelId = data.userId
            this.formData.acceptancePersonnelName = data.userName
        },

        // 结算单位处: 选择调价验收
        async settlementUnitNameClick () {
            if (this.formData.businessType === '') {
                return this.clientPop('err', '请先选择结算类型')
            }
            // this.setSelectedInfo(this.settlementData)
            // openAppClient('/showSelectedData', '数组')
            let dtlIds = []
            this.settlementData.forEach(item => {
                let dtlId = []
                item.children.forEach(it => {
                    if (it.changeType !== -1) {
                        dtlId.push(it.sourceDtlId)
                    }
                })
                dtlIds.push(...dtlId)
            })
            // this.setSelectedInfo(dtlIds)
            // openAppClient('/showSelectedData', '选择结果')
            try {
                let res = await priceSetRequest.getSettlementDialog(
                    {
                        businessType: this.formData.businessType,
                        orgId: '',
                        parentId: 0
                    },
                    dtlIds
                )
                // this.setSelectedInfo(res)
                // openAppClient('/showSelectedData', '选择结果')
                //如果点击确定时，未选择数据，即数组是空的
                if (res.length < 1) {
                    // this.businessTypeChange()
                    this.clientPop('err', '请选择结算明细！')
                    return
                }
                // 先判断所选择的数据是否都是同一个合同下的,如果不是同一个合同直接提示并且不执行后面操作
                let isSameContract = res.some(item => res[0].sourceBillId !== item.sourceBillId)
                if(isSameContract) {
                    this.clientPop('err', '只能选择相同调价验收单据的数据,请重新选择!')
                    return
                }
                let data = res.find(item => item.parentId != 0)
                // this.setSelectedInfo(data)
                // openAppClient('/showSelectedData', '选择结果')
                // 不能选择不同的合同做验收
                // if(this.formData.sourceBillId && (this.formData.sourceBillId !== data.sourceBillId)) {
                //     this.clientPop('err', '只能选择相同调价验收单据的数据,请重新选择!')
                //     return
                // }
                // val是关闭弹窗后,返回的数据
                if (!res) {
                    return
                } else {
                    // if (!Array.isArray(res)) return
                    // 如果还没有结算单位的情况,选择数据后直接赋值
                    if (
                        this.settlementData.length < 1 ||
                        !this.formData.settlementUnitId
                    ) {
                        this.assignmentFun(data)
                        this.settlementData = this.acceptanceFun(res)
                    } else if (this.formData.sourceBillId != data.sourceBillId) {
                        // 如果原有结算单位和当前选择结算单位不一致
                        this.clientPop(
                            'info',
                            '当前选择源单与原有源单不同,若点击确定,原有基本信息和结算明细将被覆盖!',
                            () => {
                                // 如果点击的确认,则处理数据格式,并把最新的数据赋值给结算明细数组
                                this.jgdwChange()
                                this.assignmentFun(data)
                                this.settlementPush(res)
                                this.subtotalFn()

                            }
                        )
                    } else{
                        this.settlementPush(res)
                        this.subtotalFn()
                    }
                }
            } catch (err) {
                alert(err.message)
            }
        },
        // 处理弹窗获取回来的数据格式
        acceptanceFun (res) {
            const newArr = []
            let obj = {}
            res.forEach(item => {
                if (item.materialClassName) {
                    const topClassName = item.materialClassName.split('/')[0]
                    const topClassId = item.materialClassId.split('/')[0]
                    obj = {
                        topClassId,
                        topClassName,
                        customId: topClassId,
                        materialClassId: topClassId,
                        materialClassName: topClassName,
                        uuid: getUuid(),
                        totalAmount: null,
                        totalQuantity: null,
                        children: []
                    }
                    if (newArr.length < 1) {
                        newArr.push(obj)
                    } else {
                        let isParent = newArr.every(
                            itm => itm.topClassId !== topClassId
                        )
                        if (isParent) {
                            newArr.push(obj)
                        }
                    }

                    newArr.forEach(its => {
                        if(its.materialClassId === item.materialClassId.split('/')[0]) {
                            its.children.push({
                                uuid: getUuid(),
                                customId: getUuid(),
                                acceptanceDtlId: item.dtlId, // 验收明细id
                                acceptancePrice: item.price, //调价验收单价
                                acceptanceQuantity: item.acceptanceQuantity, // 验收数量
                                acceptanceTaxAmount: item.taxAmount, // 验收税额
                                billId: this.billid, //	验收ID
                                changeType: 1, //变更类型
                                difference: '', // 差额
                                dtlId: '', //结算明细ID
                                materialClassId: item.materialClassId
                                    .split('/')
                                    .slice(1)
                                    .join('/'), //物资类别id
                                materialClassName: item.materialClassName
                                    .split('/')
                                    .slice(1)
                                    .join('/'), // 物资类别名称
                                materialId: item.materialId, //物资id
                                materialName: item.materialName, //物资名称
                                settledAmount: 0, // 调价结算不含税金额
                                settledPrice: '', // 调价结算单价
                                settledQuantity: item.acceptanceQuantity, // 调价结算数量
                                sourceAdjustmentSettlementDtlId: item.dtlId, //源单明细id
                                spec: item.spec, //规格型号
                                taxAmount: 0, // 税额
                                taxDifference: '', // 税额差额
                                texture: item.texture, //材质
                                unit: item.unit, //计量单位
                                warehouseId: item.warehouseId, //仓库id
                                warehouseName: item.warehouseName // 仓库名称
                            })
                        }
                        // 统计小计
                        const count = +(its.children
                            .reduce(
                                (prev, c) => (prev += +c.settledAmount || 0),
                                0
                            ))
                            .toFixed(2)
                        its.materialName = `金额小计： ${count}`
                    })
                }
            })
            return newArr
        },
        assignmentFun (data) {
            this.formData.settlementUnitName = data.supplierName // 结算单位名称
            this.formData.settlementUnitId = data.supplierId // 结算单位id
            this.formData.sourceBillNo = data.sourceBillNo // 源单编号
            this.formData.sourceBillId = data.sourceBillId // 源单ID
            this.formData.currency = data.currency // 币种名称
            this.formData.currencyId = data.currencyId // 币种ID
            this.formData.baseCurName = data.baseCurName // 本位币名称
            this.formData.baseCurId = data.baseCurId // 本位币ID
            this.formData.baseCurRate = data.baseCurRate // 本位币汇率
            this.formData.taxRate = data.taxRate || 0 // 物资采购合同：带入合同税率。
        },

        settlementPush (res) {
            let newArr = this.acceptanceFun(res)
            newArr.forEach(item => {
                const topClassIdRp = this.settlementData.every(
                    itm => itm.topClassId != item.topClassId
                )
                // 遍历当前选择数据的每一项父级id是否存在于原有数组中,如果没有,则直接添加
                if (topClassIdRp) {
                    this.settlementData.push(item)
                } else {
                    // 如果数组中的父级id一样,则返回一样的那一项的父级数据
                    const target = this.settlementData.find(
                        its => its.topClassId == item.topClassId
                    )
                    // 给这条父级数据的children里面添加子级
                    item.children.forEach(it => {
                        // 如果当前父级的子级中没有相同的,则直接添加
                        const materialIdRp = target.children.every(
                            _it => _it.materialId != it.materialId
                        )
                        if (materialIdRp) {
                            target.children.push(it)
                        } else {
                            // 遍历出所有子级id一样的
                            const _target = target.children.filter(
                                i => i.materialId == it.materialId
                            )
                            // 如果当前遍历的子项存在于原数组,但是changeTpye等于-1说明已经删除,那还是可以重新添加进入的,changeType不等于-1的,不做操作;如果遍历完了都是等于-1的,才添加
                            const noPush = _target.some(
                                _i => _i.changeType !== -1
                            )
                            if (!noPush) {
                                target.children.push(it)
                            }
                        }
                    })
                }
            })
        },
        subtotalFn () {
            let count = 0
            let countSum = 0
            this.settlementData.forEach(item => {
                count = +(item.children
                    .reduce(
                        (pre, c) => pre += (+c.settledAmount || 0),
                        0
                    ))
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
                countSum += +count
            })
            this.formData.amount = +(+countSum).toFixed(2)
            this.taxDifferenceFn()
            // this.setSelectedInfo(JSON.parse(JSON.stringify(this.settlementData)))
            // openAppClient('/showSelectedData', '选择结果')
        },

        // 如果业务类型变化,需清除带入的数据
        businessTypeChange () {
            this.formData.settlementUnitName = ''
            this.formData.settlementUnitId = ''
            this.formData.sourceBillNo = ''
            this.formData.sourceBillId = ''
            this.formData.currency = ''
            this.formData.currencyId = ''
            this.formData.baseCurName = ''
            this.formData.baseCurId = ''
            this.formData.baseCurRate = ''
            this.formData.taxRate = ''
            this.formData.amount = ''
            this.jgdwChange()
        },
        jgdwChange () {
            // 当业务类型变化了或者供应商变了,需要处理结算明细的数据,不含税金额,税额等都需重新计算
            for (let i = 0; i < this.settlementData.length; i++) {
                for (
                    let m = 0;
                    m < this.settlementData[i]['children'].length;
                    m++
                ) {
                    if (this.settlementData[i]['children'][m]['dtlId']) {
                        this.$set(
                            this.settlementData[i]['children'][m],
                            'changeType',
                            -1
                        )
                        this.$set(
                            this.settlementData[i]['children'][m],
                            'settledAmount',
                            0
                        )
                        this.$set(
                            this.settlementData[i]['children'][m],
                            'taxAmount',
                            0
                        )
                        this.$set(
                            this.settlementData[i]['children'][m],
                            'taxDifference',
                            0
                        )
                        this.$set(
                            this.settlementData[i]['children'][m],
                            'acceptanceTaxAmount',
                            0
                        )
                    } else {
                        this.settlementData[i]['children'].splice(m, 1)
                        m--
                    }
                }
            }
            // this.setSelectedInfo(JSON.stringify(this.settlementData))
            // openAppClient('/showSelectedData', '选择结果')
            this.formData.amount = 0
            this.formData.taxDifference  = 0
            // 需要把删除数据后的结算明细数据给一个空数组存起来,最后在保存时拼接上一并传给后端
            // this.settlementDelData.push(...this.settlementData)
            // 服务费用也需要清空
            for (let i = 0; i < this.serviceFeeData.length; i++) {
                if (this.serviceFeeData[i]['dtlId']) {
                    this.$set(
                        this.serviceFeeData[i],
                        'changeType',
                        -1
                    )
                    this.$set(
                        this.serviceFeeData[i],
                        'totalAmount',
                        0
                    )
                    this.$set(
                        this.serviceFeeData[i],
                        'amount',
                        0
                    )
                } else {
                    this.serviceFeeData.splice(i, 1)
                    i--
                }
            }
            this.formData.freight = 0
        },
        // 税率只能输入0-100的数
        onInput0_100 (e) {
            this.$message.closeAll()
            if (e.target.value < 0 || e.target.value > 100) {
                this.$message.warning('只能输入[0,100]区间的数')
            }
            e.target.value =
                (e.target.value >= 0 &&
                    e.target.value <= 100 &&
                    e.target.value.match(/^\d{1,3}(\.\d*)?$/)[0]) ||
                null
        },
        // // 本位币汇率失去焦点时
        baseCurRateBlur () {
            if (this.formData.baseCurRate == 0) {
                this.formData.baseCurRate = null
            }
            this.formData.baseCurAmount =
                +this.formData.amount * +this.formData.baseCurRate
        },
        // // 当币种切换时,获取人民币汇率
        // currencyChange (val) {
        //     this.formData.currency = this.currencyForm.find(
        //         x => x.value === val
        //     ).label //币种名称
        // },

        // ------------------------------结算明细---------------------------------------

        // 获取结算明细表格数据(弹窗好了过后最终需要调的接口)
        async getSettlementList () {
            let res = await priceSetRequest.getSettlementList(this.billid)
            if (!Array.isArray(res)) return
            res.forEach(item => {
                item.materialClassName = item.topClassName
                item.uuid = getUuid()
                item.children.forEach(i => {
                    i.uuid = i.dtlId
                })
                const count = +(item.children
                    .reduce((prev, c) => (prev += +c.settledAmount || 0), 0))
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
            })
            this.settlementData = res
        },
        //  计算基本信息中的税额差额
        taxDifferenceFn () {
            let count = 0
            let countSum = 0
            this.settlementData.forEach(item => {
                count = +(item.children.reduce((prev, c) => prev + (+c.taxDifference || 0), 0))
                countSum += +count
            })
            this.formData.taxDifference = +(+countSum).toFixed(2)
        },

        // 监听调价结算数量
        settledQuantityBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (
                +row.acceptanceQuantity &&
                +row.settledQuantity > +row.acceptanceQuantity
            ) {
                this.clientPop(
                    'err',
                    `不能大于未验收数量${row.acceptanceQuantity}`
                )
                row.settledQuantity = row.acceptanceQuantity
            }
            // 计算调价结算单价 = 调价结算金额 / 结算数量
            if (+row.settledAmount && +row.settledQuantity) {
                row.settledPrice = +(
                    +row.settledAmount / +row.settledQuantity
                ).toFixed(2)
            } else {
                row.settledPrice = 0
            }

            // 计算价差 = 调价结算数量*（调价结算单价-调价验收单价）
            if (
                +row.settledQuantity &&
                +row.settledPrice &&
                +row.acceptancePrice
            ) {
                row.difference = +(
                    +row.settledQuantity *
                    (+row.settledPrice - +row.acceptancePrice)
                ).toFixed(2)
            } else {
                row.difference = 0
            }

        },

        // 监听调价结算金额
        settledAmountBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            // 计算调价单价 = 调价结算金额 / 结算数量
            if (+row.settledAmount && +row.settledQuantity) {
                row.settledPrice = +(
                    +row.settledAmount / +row.settledQuantity
                ).toFixed(2)
            } else {
                row.settledPrice = 0
            }
            // 计算价差 = 调价结算数量*（调价结算单价-调价验收单价）
            if (
                +row.settledQuantity &&
                +row.settledPrice &&
                +row.acceptancePrice
            ) {
                row.difference = +(
                    +row.settledQuantity *
                    (+row.settledPrice - +row.acceptancePrice)
                ).toFixed(2)
            } else {
                row.difference = 0
            }
            // 金额变化时, 税额会跟着变化,清单的调价结算金额*基本信息中税率
            row.taxAmount = +(+row.settledAmount * (+this.formData.taxRate / 100)).toFixed(2)
            // 税额差额 = 税额-调价验收单中物资明细的税额
            if(+row.taxAmount && +row.acceptanceTaxAmount) {
                row.taxDifference = +(+row.taxAmount - +row.acceptanceTaxAmount).toFixed(2)
            }
            // 计算基本信息的结算金额
            let count = 0
            let countSum = 0
            this.settlementData.forEach(item => {
                count = +(item.children
                    .reduce((prev, c) => (prev += +c.settledAmount || 0), 0))
                    .toFixed(2)
                item.materialName = `金额小计： ${count}`
                countSum += +count
            })
            this.formData.amount = +countSum.toFixed(2)

        },

        // 如果changeType是删除,则隐藏这一行
        tableRowClassName ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            if(row.children) {
                if(row.children.length < 1) {
                    return 'warning-row'
                }else {
                    let isDel = row.children.every(it => it.changeType === -1)
                    if(isDel) {
                        return 'warning-row'
                    }
                }
            }
            return ''
        },

        // 复选框选中的数据
        acceptanceSelect (selection) {
            this.settlementList = selection.filter(
                item => item.changeType !== -1
            )
        },
        // 点击批量删除
        // acceptanceDeleteClick () {
        //     const length = this.settlementList.length
        //     if (length === 0) {
        //         this.clientPop('info', '你还未选择数据,请选择!')
        //     } else {
        //         this.clientPop(
        //             'info',
        //             this.moreDeleteErr(length),
        //             this.settlementDeleteList
        //         )
        //     }
        // },
        // 批量删除
        // settlementDeleteList () {
        //     this.settlementList.filter(row => {
        //         if (row.dtlId) {
        //             this.settlementData.forEach(item => {
        //                 const index = item.children.findIndex(
        //                     its => its.dtlId === row.dtlId
        //                 )
        //                 this.$set(item.children[index], 'changeType', -1)
        //                 this.$set(item.children[index], 'settledAmount', 0)
        //             })
        //         } else {
        //             this.settlementData.forEach(item => {
        //                 item.children.forEach((its, index) => {
        //                     if (this._.isEqual(its, row)) {
        //                         item.children.splice(index, 1)
        //                     }
        //                 })
        //             })
        //         }
        //     })
        //     this.$refs.settlementTable.clearSelection()
        //     let count = 0
        //     let countSum = 0
        //     this.settlementData.forEach(item => {
        //         count = +(item.children
        //             .reduce((pre, c) => (pre += +c.settledAmount || 0), 0))
        //             .toFixed(2)
        //         item.materialName = `金额小计： ${count}`
        //         countSum += +Number((+count).toFixed(2))
        //     })
        //     this.formData.amount = countSum
        // },

        // ---------------------------------服务明细---------------------------------
        // 点击新增行
        serviceFeeAdd () {
            this.serviceFeeData.push({
                amount: '',
                billId: '',
                changeType: 0,
                contractBillId: '',
                contractBillNo: '',
                contractBillType: '',
                contractDtlId: '',
                contractDtlName: '',
                contractQuantity: '',
                dtlId: '',
                invoiceNo: '',
                price: '',
                quantity: '',
                settlementUnitId: '',
                settlementUnitName: '',
                sourceServiceFeeDtlId: '',
                taxAmount: 0,
                taxRate: 0,
                totalAmount: 0
            })
        },

        // 获取服务费用表格数据(弹窗做好后,需要放开注释的)
        async getServeList () {
            let res = await priceSetRequest.getServeList(this.billid)
            if (Array.isArray(res)) {
                this.serviceFeeData = res
            }
        },

        // 结算单位弹窗选择点击保存后
        async billingUnitDialog (row, index) {
            // this.setSelectedInfo(this.jsdwData)
            // openAppClient('/showSelectedData', '选择结果')
            this.jsdwIds = row.settlementUnitId
            let res = await request.getBillingUnit(this.jsdwData, this.jsdwIds)
            // async getServeList () { // 弹窗好了,需删除这行
            //     let res = await request.getServeList(this.billingUnitQuery) // 弹窗好了,需删除这行
            let result = {
                amount: null,
                billId: this.billid,
                changeType: 1,
                contractBillId: '',
                contractBillNo: '',
                contractBillType: '',
                contractDtlId: '',
                contractDtlName: '',
                contractQuantity: '',
                dtlId: '',
                invoiceNo: '',
                price: null,
                quantity: null,
                settlementUnitId: res.id,
                settlementUnitName: res.outerName,
                sourceServiceFeeDtlId: '',
                taxAmount: 0,
                taxRate: 0,
                totalAmount: 0
            }
            const shouldPush = this.serviceFeeData.every(
                it => it.settlementUnitId !== result.settlementUnitId
            )
            if (shouldPush) {
                this.serviceFeeData.splice(index, 1, result)
            } else {
                const repeatArr = this.serviceFeeData.filter(
                    i => i.settlementUnitId === result.settlementUnitId
                )
                const noPush = repeatArr.some(_its => _its.changeType !== -1)
                if (!noPush) {
                    this.serviceFeeData.splice(index, 1, result)
                }
            }
            this.formData.freight = +(this.serviceFeeData
                .reduce((pre, c) => (pre += +c.totalAmount || 0), 0))
                .toFixed(2)
        },

        // })
        // },

        // 合同选择弹窗
        //  选择合同的接口由胡腾提供,合同的数据是从 物资采购合同服务清单,物流运输类服务采购合同清单
        async contractDialog (row, index) {
            let contracted = {
                contractId: row.contractBillId,
                contractType: row.contractBillType || 0
            }
            let res = await request.getContract(
                { orgid: this.orgId, contractId: this.formData.sourceBillId, contractType: '1'  },
                contracted
            )
            // this.setSelectedInfo(res)
            // openAppClient('/showSelectedData', '选择结果')
            let result
            // 如果选择的是合同并且合同下有清单,则需带入合同下的清单
            if (res.list && res.list.length > 0) {
                result = res.list.map(item => {
                    return {
                        amount: null,
                        billId: this.billid,
                        changeType: 1,
                        contractBillId: res.contractId,
                        contractBillNo: res.contractNumber,
                        contractBillType: '',
                        contractDtlId: item.detailedId,
                        contractDtlName: item.name,
                        contractQuantity: item.quantity, // 这个字段是用于在修改数量时,不能大于合同数量的
                        dtlId: '',
                        invoiceNo: '',
                        price: null,
                        quantity: item.quantity,
                        settlementUnitId: res.secondPartyId,
                        settlementUnitName: res.secondPartyName,
                        sourceServiceFeeDtlId: '',
                        taxAmount: 0,
                        taxRate: res.taxRate,
                        totalAmount: 0
                    }
                })
                let _arr = []
                result.forEach(item => {
                    const shouldPush = this.serviceFeeData.every(
                        it => item.contractDtlId !== it.contractDtlId
                    )
                    if (shouldPush) {
                        _arr.push(item)
                    } else {
                        // 找到了清单ID相同
                        const repeatArr = this.serviceFeeData.filter(
                            i => item.contractDtlId === i.contractDtlId
                        )
                        const noPush = repeatArr.some(
                            _its => _its.changeType !== -1
                        )
                        if (!noPush) {
                            _arr.push(item)
                        }
                    }
                })
                if (_arr.length !== 0) {
                    this.serviceFeeData.splice(index, 1, ..._arr)
                }
            } else {
                // 如果选择的合同没有清单
                result = {
                    amount: null,
                    billId: this.billid,
                    changeType: 1,
                    contractBillId: res.contractId,
                    contractBillNo: res.contractNumber,
                    contractBillType: '',
                    contractDtlId: '',
                    contractDtlName: '',
                    contractQuantity: '',
                    dtlId: '',
                    invoiceNo: '',
                    price: null,
                    quantity: null,
                    settlementUnitId: res.secondPartyId,
                    settlementUnitName: res.secondPartyName,
                    sourceServiceFeeDtlId: '',
                    taxAmount: 0,
                    taxRate: res.taxRate,
                    totalAmount: 0
                }
                const shouldPush = this.serviceFeeData.every(
                    it => it.contractBillId !== result.contractBillId
                )
                if (shouldPush) {
                    this.serviceFeeData.splice(index, 1, result)
                } else {
                    const repeatArr = this.serviceFeeData.filter(
                        i => i.contractBillId === result.contractBillId
                    )
                    const noPush = repeatArr.some(
                        _its => _its.changeType !== -1
                    )
                    if (!noPush) {
                        this.serviceFeeData.splice(index, 1, result)
                    }
                }
            }
            this.formData.freight = +(this.serviceFeeData
                .reduce((pre, c) => (pre += +c.totalAmount || 0), 0))
                .toFixed(2)
        },
        // 清单名称
        contractDtlNameBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
        },

        // 数量变化时
        quantityBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            // 不能超过合同数量
            if (+row.contractQuantity) {
                if (+row.quantity > +row.contractQuantity) {
                    this.clientPop(
                        'err',
                        `不能大于合同数量${row.contractQuantity}`
                    )
                    row.quantity = row.contractQuantity
                }
            }
            if (+row.amount && +row.quantity) {
                row.price = +(+row.amount / +row.quantity).toFixed(2)
            } else {
                row.price = 0
            }
        },
        // 金额变化时
        amountBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (+row.amount && +row.quantity) {
                row.price = +(+row.amount / +row.quantity).toFixed(2)
            } else {
                row.price = 0
            }
            if (+row.amount && +row.taxRate) {
                row.taxAmount = +(+row.amount * (+row.taxRate / 100)).toFixed(2)
            } else {
                row.taxAmount = 0
            }
            if (+row.amount && +row.taxAmount) {
                row.totalAmount = +(
                    (+row.amount * 100 + +row.taxAmount * 100) /
                    100
                ).toFixed(2)
            } else {
                row.totalAmount = 0
            }
            this.formData.freight = +(this.serviceFeeData
                .reduce((pre, c) => (pre += +c.totalAmount || 0), 0))
                .toFixed(2)
        },
        invoiceNoBlur (row) {
            row.changeType === 1 ? row.changeType = 1 : row.changeType = 2
        },

        // 税率变化时
        taxRateBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (+row.amount && +row.taxRate) {
                row.taxAmount = +(+row.amount * (+row.taxRate / 100)).toFixed(2)
            } else {
                row.taxAmount = 0
            }
            if (+row.amount && +row.taxAmount) {
                row.totalAmount = +(
                    (+row.amount * 100 + +row.taxAmount * 100) /
                    100
                ).toFixed(2)
            } else {
                row.totalAmount = 0
            }
        },
        //税额变化时
        taxAmountBlur (row) {
            if (row.changeType == 1) {
                row.changeType = 1
            } else {
                row.changeType = 2
            }
            if (+row.amount && +row.taxAmount) {
                row.totalAmount = +(
                    (+row.amount * 100 + +row.taxAmount * 100) /
                    100
                ).toFixed(2)
            } else {
                row.totalAmount = 0
            }
        },

        // 服务费用单条删除
        serviceFeeDelete (row, index) {
            this.clientPop('info', this.oneDeleteErr, () => {
                if (row.dtlId) {
                    // 如果有明细id,说明是已经存在后端数据库中的数据,已存在的数据,在删除时只能将changType设为-1
                    this.$set(row, 'changeType', -1)
                } else {
                    // 没有明细id,说明是刚新增的数据,直接在原数组中删除即可
                    this.serviceFeeData.splice(index, 1)
                }
                row.amount = 0
                row.totalAmount = 0
                this.formData.freight = +(this.serviceFeeData
                    .reduce((pre, c) => (pre += +c.totalAmount || 0), 0))
                    .toFixed(2)
            })
        },
        tableRowClassNameF ({ row }) {
            if (row.changeType === -1) {
                return 'warning-row'
            }
            return ''
        },

        // 复选框选中的数据
        serviceFeeSelect (selection) {
            this.serviceFeeList = selection.filter(
                item => item.changeType !== -1
            )
        },
        // 点击批量删除
        serviceFeeDeleteClick () {
            const length = this.serviceFeeList.length
            if (length === 0) {
                this.clientPop('info', '你还未选择数据,请选择!')
            } else {
                this.clientPop(
                    'info',
                    this.moreDeleteErr(length),
                    this.serviceFeeDeleteList
                )
            }
        },
        // 批量删除
        serviceFeeDeleteList () {
            this.serviceFeeList.filter(row => {
                if (row.dtlId) {
                    const index = this.serviceFeeData.findIndex(item => {
                        return item.dtlId == row.dtlId
                    })
                    this.$set(this.serviceFeeData[index], 'changeType', -1)
                    this.$set(this.serviceFeeData[index], 'amount', 0)
                    this.$set(this.serviceFeeData[index], 'totalAmount', 0)
                } else {
                    this.serviceFeeData.forEach((item, index) => {
                        if (this._.isEqual(item, row)) {
                            this.serviceFeeData.splice(index, 1)
                        }
                    })
                }
            })
            this.$refs.serviceFeeTable.clearSelection()
            this.formData.freight = +(this.serviceFeeData
                .reduce((pre, c) => (pre += +c.totalAmount || 0), 0))
                .toFixed(2)
        },

        // -------------------在点击下面几个按钮前,需要做前置判断-------------------------
        //设置错误标签
        setError (name) {
            if (!this.errorList.find(x => x === name)) {
                this.errorList.push(name)
            }
        },
        //清除错误标签
        clearError (name) {
            const index = this.errorList.findIndex(x => x === name)
            if (index !== -1) {
                this.errorList.splice(index, 1)
            }
        },
        //跳转到第一个错误标签
        scorllError () {
            let num = this.tabArr.length
            this.errorList.forEach(item => {
                let index = this.tabArr.findIndex(x => x === item)
                num = index < num ? index : num
            })
            const obj = { name: this.tabArr[num] }
            this.tabsName = this.tabArr[num]
            this.onChangeTab(obj)
        },
        // 设置结算明细有错误时在表格上面显示的错误信息
        setErrorSettlementMsg (msg) {
            let index = this.errorSettlementMsg.findIndex(x => x === msg)
            if (index === -1) {
                this.errorSettlementMsg.push(msg)
            }
        },
        // 设置服务费用有错误时在表格上面显示的错误信息
        setErrorServiceFeeMsg (msg) {
            let index = this.errorServiceFeeMsg.findIndex(x => x === msg)
            if (index === -1) {
                this.errorServiceFeeMsg.push(msg)
            }
        },
        // 点击左边的Tab标签
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        //保存基本信息时需要检测的
        updateBaseInfo () {
            return new Promise((resolve, reject) => {
                this.$refs.formDataRef.validate(valid => {
                    if (valid) {
                        if (this.formData.redBillState == 3) {
                            this.redFormData.remarks = this.formData.remarks
                        }
                        priceSetRequest
                            .basicInfoSave(
                                this.formData.redBillState == 3
                                    ? this.redFormData
                                    : this.formData
                            )
                            .then(() => {
                                this.clearError('baseInfo')
                                resolve()
                            })
                            .catch(err => {
                                reject(err)
                                this.setError('baseInfo')
                            })
                    } else {
                        this.setError('baseInfo')
                        reject('基本信息错误')
                    }
                })
            })
        },
        // 保存结算明细时需要检测的
        saveSettlement () {
            this.errorSettlementMsg = []
            return new Promise((resolve, reject) => {
                if (this.isSubmit) {
                    // 如果点击的是提交审核才需要判断结算明细是否为空,为空时不能提交审核
                    if (this.settlementData.length < 1) {
                        this.setErrorSettlementMsg('请选择需结算的数据')
                        this.setError('settlement')
                        reject('结算明细错误')
                        return
                    } else {
                        // 如果每一个子项的changeType都为 -1  就说明都删除了, 那就不能提交审核
                        let arr = []
                        this.settlementData.forEach(item => {
                            let isData = item.children.every(
                                its => its.changeType === -1
                            )
                            arr.push(isData)
                        })
                        let isSubmit = arr.every(i => i === true)
                        if (isSubmit) {
                            this.setErrorSettlementMsg('请选择需结算的数据')
                            this.setError('settlement')
                            reject('结算明细错误')
                            return
                        }
                    }
                }
                this.settlementData.forEach(its => {
                    // 只需验证顶级的物资类别是否有
                    !its.materialClassName
                        ? this.setErrorSettlementMsg('请填写物资类别')
                        : ''
                    its.children.forEach(item => {
                        if (item.changeType !== -1) {
                            !item.materialName
                                ? this.setErrorSettlementMsg('请填写物资名称')
                                : ''
                            !item.unit
                                ? this.setErrorSettlementMsg('请填写计量单位')
                                : ''
                            !item.warehouseName
                                ? this.setErrorSettlementMsg('请填写仓库')
                                : ''
                            item.settledQuantity === '' ||
                            item.settledQuantity === null
                                ? this.setErrorSettlementMsg(
                                    '请填写调价结算数量'
                                )
                                : ''
                            item.settledPrice === '' ||
                            item.settledPrice === null || isNaN(item.settledPrice)
                                ? this.setErrorSettlementMsg(
                                    '请计算调价结算单价'
                                )
                                : ''
                            item.settledAmount === '' ||
                            item.settledAmount === null || isNaN(item.settledAmount)
                                ? this.setErrorSettlementMsg(
                                    '请填写调价结算不含税金额'
                                )
                                : ''
                            item.acceptancePrice === '' ||
                            item.acceptancePrice === null
                                ? this.setErrorSettlementMsg(
                                    '请带出调价验收单价'
                                )
                                : ''
                        }
                    })
                })
                if (this.errorSettlementMsg.length > 0) {
                    this.setError('settlement')
                    reject('结算明细错误')
                    return
                } else {
                    this.settlementData.push(...this.settlementDelData)
                    // this.setSelectedInfo(this.settlementData)
                    // openAppClient('/showSelectedData', '选择结果')
                    priceSetRequest
                        .saveSettlement(this.settlementData)
                        .then(() => {
                            this.getSettlementList()
                            this.clearError('settlement')
                            resolve()
                        })
                        .catch(err => {
                            this.errorSettlementMsg[0] = err.message
                            this.setError('settlement')
                            reject(err)
                        })
                }
            })
        },
        // 保存服务明细时需要检测的
        saveServiceFee () {
            this.errorServiceFeeMsg = []
            return new Promise((resolve, reject) => {
                // 如果是基本信息处验结一体勾选中，则服务费用明细中发票编号必填
                if (this.formData.isAccepSettle) {
                    this.serviceFeeData.every(item => {
                        if (!item.invoiceNo) {
                            return this.setErrorServiceFeeMsg('请填写发票编号')
                        }
                    })
                }
                // 检测必填项是否全部填写完毕
                this.serviceFeeData.forEach(item => {
                    if (item.changeType !== -1) {
                        !item.settlementUnitName
                            ? this.setErrorServiceFeeMsg('请填写结算单位')
                            : ''
                        !item.contractDtlName
                            ? this.setErrorServiceFeeMsg('请填写清单名称')
                            : ''
                        !item.quantity
                            ? this.setErrorServiceFeeMsg('请填写数量')
                            : ''
                        item.price === '' || item.price === null || isNaN(item.price)
                            ? this.setErrorServiceFeeMsg('请填写单价(元)')
                            : ''
                        item.amount === '' || item.amount === null || isNaN(item.amount)
                            ? this.setErrorServiceFeeMsg('请填写金额(元)')
                            : ''
                        item.totalAmount === '' || item.totalAmount === null || isNaN(item.totalAmount)
                            ? this.setErrorServiceFeeMsg('请填写税价合计(元)')
                            : ''
                    }
                })
                if (this.errorServiceFeeMsg.length > 0) {
                    this.setError('serviceCharge')
                    reject('服务费用错误')
                    return
                } else {
                    // 如果必填项已全部填完,那么才发送保存服务费用的接口,如果报错依然需要定位到具体位置
                    priceSetRequest
                        .saveServiceFee(this.serviceFeeData)
                        .then(() => {
                            this.getServeList()
                            this.clearError('serviceCharge')
                            resolve()
                        })
                        .catch(err => {
                            this.errorServiceFeeMsg[0] = err.message
                            this.setError('serviceCharge')
                            reject(err)
                        })
                }
            })
        },
        // 保存所有数据
        saveAll () {
            showLoading()
            this.errorList = []
            // 汇总验收数量
            let count = 0
            let countSum = 0
            this.settlementData.forEach(item => {
                count = +(item.children
                    .reduce((pre, c) => (pre += +c.acceptanceQuantity || 0), 0))
                    .toFixed(2)
                countSum += +count
            })
            this.formData.acceptanceQuantity = +countSum.toFixed(2)
            Promise.all([
                this.updateBaseInfo(),
                this.saveSettlement(),
                this.saveServiceFee()
            ])
                .then(() => {
                    hideLoading()
                    this.clientPop('suc', '保存成功')
                })
                .catch(err => {
                    console.log('errMsg：', err)
                    // this.clientPop('err', '保存失败', () => {
                    this.scorllError()
                    // })
                })
                .finally(() => {
                    hideLoading()
                })
        },
        // 提交审核
        submitReview () {
            showLoading()
            this.errorList = []
            Promise.all([
                this.updateBaseInfo(),
                this.saveSettlement(),
                this.saveServiceFee()
            ])
                .then(() => {
                    // 需要验证基本信息中税价合计和服务费用两者不能同时为0
                    if(this.formData.totalAmount == 0 && this.formData.freight == 0) {
                        this.clientPop('err', '税价合计和服务费用，两者不可同时为0。')
                        return
                    }
                    request.commitAudit(this.auditParams)
                    this.clientPop('suc', '提交成功', this.handleClose)
                })
                .catch(err => {
                    console.log('errMsg：', err)
                    // this.clientPop('err', '提交失败', () => {
                    this.scorllError()
                    // })
                })
                .finally(() => {
                    hideLoading()
                })
        },

        // 审核
        onAudit () {
            showLoading()
            this.setAuditParams(this.auditParams)
            // 客户端弹窗弹出本地页面
            openAppClient('/exaDialog', '填写审核意见', () => {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                showLoading()
                request
                    .audit(auditParams)
                    .then(() => {
                        this.clientPop('suc', '审核成功', this.handleClose)
                    })
                    .finally(() => {
                        hideLoading()
                    })
            }, null, null, null, 'small')
        },

        // 撤销审核
        undoAudit () {
            showLoading()
            request
                .undoAudit(this.auditParams)
                .then(() => {
                    this.clientPop('suc', '撤回成功', this.handleClose)
                })
                .finally(() => {
                    hideLoading()
                })
        },
        // 作废
        nullify () {
            this.setAuditParams(this.nullifyParams)
            // 客户端弹窗弹出本地页面
            openAppClient('/nullifyDialog', '单据作废原因', () => {
                const auditParams = JSON.parse(localStorage.vuex).auditParams
                showLoading()
                request
                    .nullify(auditParams)
                    .then(() => {
                        this.clientPop('suc', '作废成功', this.handleClose)
                    })
                    .finally(() => {
                        hideLoading()
                    })
            }, null, null, null, 'small')
        },
        // 删除
        deleteData () {
            this.clientPop('info', this.oneDeleteErr, () => {
                showLoading()
                priceSetRequest
                    .basicInfoDelete(this.billid)
                    .then(() => {
                        this.clientPop('suc', '删除成功', this.handleClose)
                    })
                    .finally(() => {
                        hideLoading()
                    })
            })
        },

        // ---------------------------下面按钮---------------------------
        // 获取按钮状态
        async getUnitInfo () {
            this.auditState = await request.getCurrentUnitInfo(
                this.auditParams
            )
        },

        // 点击下面几个不同的按钮做不同的操作
        exas (arg) {
            if (arg === 'submit') {
                this.isSubmit = false
                this.saveAll() // 保存所有数据
            } else if (arg === 'submitCommit') {
                this.isSubmit = true
                this.submitReview() // 保存并提交
            } else if (arg === 'audit') {
                this.onAudit() // 审核
            } else if (arg === 'undoAudit') {
                this.undoAudit() // 撤销审核
            } else if (arg === 'nullify') {
                this.nullify() // 作废
            } else if (arg === 'deleteData') {
                this.deleteData() // 删除
            }
        },

        // ------------------------上面小刘---------

        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('auditHistoryCon')) {
                    const lastConHeight =
                        document.getElementById('auditHistoryCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    console.log('this.lastConHeight', this.lastConHeight)
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },

        //查询附件信息
        getAttach () {
            this.objFlag.flag5 = true
        },
        //关闭
        handleClose () {
            hideLoading()
            this.$router.replace('/priceSettlementList')
        },
        showState (state) {
            const _state = this.$store.state.settlementManagement.ysState
            const obj = _state.find(x => x.value === Number(state))
            return obj.label
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    margin-bottom: 80px;
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}

.e-table {
    background: #fff;
}
::v-deep.el-table .warning-row {
    display: none;
}
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
    width: 6px; // 横向滚动条
    height: 10px; // 纵向滚动条
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 5px;
}

.el-tab-pane {
    margin-left: -10px;
}
::v-deep .el-table__fixed{
        height: 100% !important
}
</style>
